public class Solution {
    
    public List<List<String>> groupStrings(String[] strings) {
        if(strings == null)
            throw new IllegalArgumentException("strings is null");
        List<List<String>> ret = new ArrayList<List<String>>();
        if(strings.length == 0)
            return ret;
        Map<String, List<String>> map = new HashMap<String, List<String>>();
        for(String str : strings) {
            String shifted_str = shiftStr(str);
            if(map.containsKey(shifted_str)) {
                map.get(shifted_str).add(str);
            } else {
                List<String> item = new ArrayList<String>();
                item.add(str);
                map.put(shifted_str, item);
                ret.add(item);
            }
        }
        return ret;
    }
    
    public String shiftStr(String str) {
        String key = "";
        for(int i = 0; i < str.length() - 1; i++) {
            char c1 = str.charAt(i);
            char c2 = str.charAt(j);
            int gap = c1 > c2 ? c1 - c2 : c1 - c2 + 26;
            char num = 'a' + gap;
            key += num;
        }
        return key;
    }
    
}